package com.example.edianzu.somur.utils.adaptetr;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * author：风不会停息 on 2017/7/21 17:52
 * mailbox：yh131412hys@163.com
 * project：Somur
 * tel：13295355900
 * describe：
 */

public abstract class BaseListViewAdapter<T> extends BaseAdapter{

    private List<T> datas;
    private Context context;
    private LayoutInflater layoutInflater;

    public BaseListViewAdapter(Context context) {
        this.context = context;
        datas=new ArrayList<>();
        layoutInflater=LayoutInflater.from(context);
    }

    public void add(List<T> data){

        datas.addAll(data);
        notifyDataSetChanged();
    }

    public void add(T data){

        datas.add(data);
        notifyDataSetChanged();
    }

    public Context getContext() {
        return context;
    }

    public LayoutInflater getLayoutInflater() {
        return layoutInflater;
    }

    public void clear(){

        datas.clear();
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return datas!=null?datas.size():0;
    }

    @Override
    public T getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
}
